package com.hpin.fansea.home;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.base.BaseActivity;
import com.hpin.fansea.bean.RadioResult;
import com.hpin.fansea.widget.PreviewPhotoActivity;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 小区广播详情页面
 * Created by Aaron on 15/9/17.
 */
public class BroadcastDetailActivity extends BaseActivity {

    private RadioResult.CellBroadcastList cellBroadcast;
    private TextView radio_detail_title;
    private TextView radio_detail_content;
    private TextView radio_detail_date;
    private ImageView radio_detail_img;
    public DisplayImageOptions options;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_broadcast_detail);

        cellBroadcast = (RadioResult.CellBroadcastList) getIntent().getSerializableExtra("broadcastDetail");

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.icon_loading_big_default)
                .showImageForEmptyUri(R.mipmap.icon_fail_big_default)
                .showImageOnFail(R.mipmap.icon_fail_big_default)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new SimpleBitmapDisplayer()).build();


        initWidget();

        setData();
    }

    private void initWidget() {

        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);

        tv_title.setText(getResources().getString(R.string.community_broadcast));

        iv_left.setOnClickListener(this);

        radio_detail_title = (TextView) findViewById(R.id.radio_detail_title);
        radio_detail_img = (ImageView) findViewById(R.id.radio_detail_img);
        radio_detail_content = (TextView) findViewById(R.id.radio_detail_content);
        radio_detail_date = (TextView) findViewById(R.id.radio_detail_date);

        radio_detail_img.setOnClickListener(this);
    }

    /**
     * 设置数据
     */
    private void setData() {

        radio_detail_title.setText(cellBroadcast.cbName);

        radio_detail_content.setText(cellBroadcast.cbContent);

        radio_detail_date.setText(cellBroadcast.createTime);

        if (!TextUtils.isEmpty(cellBroadcast.fmpic)) {

            ImageLoader.getInstance().displayImage(cellBroadcast.fmpic, radio_detail_img, options);

        } else {
            radio_detail_img.setVisibility(View.GONE);
        }

    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.iv_left:
                finish();
                break;

            case R.id.radio_detail_img:

                Intent mIntent = new Intent(this, PreviewPhotoActivity.class);
                List<String> picLists = new ArrayList<String>();
                picLists.add(cellBroadcast.fmpic);
                mIntent.putExtra("picLists", (Serializable) picLists);
                startActivity(mIntent);

                break;

        }
    }
}
